<?php

class Tasks_model extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }
    
    function getTask($task_id)
    {
        $SQL = "SELECT * FROM " . TASKS_TABLE . " 
                INNER JOIN " . USERS_TABLE . " on user_owner_id = user_id 
                WHERE task_id = " . $task_id;
        $query = $this->db->query($SQL);
        return $query->row_array();
    }
    
    function getLastTasks($count)
    {
        $SQL = "SELECT * FROM " . TASKS_TABLE . " 
                INNER JOIN " . USERS_TABLE . " on user_owner_id = user_id 
                WHERE task_status = 0 
                LIMIT " . $count;
        $query = $this->db->query($SQL);
        return $query->result();
    }
    
    function getTasks($count, $start)
    {
        $SQL = "SELECT * FROM " . TASKS_TABLE . " 
                INNER JOIN " . USERS_TABLE . " on user_owner_id = user_id 
                WHERE task_status = 0 
                LIMIT " .$start . ", " . $count;
        $query = $this->db->query($SQL);
        return $query->result();
    }
    
    function getTasksCount()
    {
        $SQL = "SELECT COUNT(*) as tasksCount 
				FROM " . TASKS_TABLE . " 
				WHERE task_status = 0";
        $query = $this->db->query($SQL);
        $resultQuery = $query->row();

        return $resultQuery->tasksCount;
    }
}
?>
